package com.vietnam.power.persitence;

import java.io.Serializable;

import javax.persistence.*;

import com.vietnam.power.domain.Root;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the transaction database table.
 * 
 */
@Entity
@Table(name="transaction")
public class Transaction implements Serializable, Root {
	private static final long serialVersionUID = 1L;
	private int id;
	private Date createdDate;
	private int orderStatus;
	private String remark;
	private BigDecimal totalPaid;
	private String transactionRefNumber;
	private List<TxnProduct> txnProducts;
	private PatronInfo patronInfo;
	private PaymentMethod paymentMethod;

	public Transaction() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "created_date")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	@Column(name = "order_status")
	public int getOrderStatus() {
		return this.orderStatus;
	}

	public void setOrderStatus(int orderStatus) {
		this.orderStatus = orderStatus;
	}

	@Lob
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "total_paid")
	public BigDecimal getTotalPaid() {
		return this.totalPaid;
	}

	public void setTotalPaid(BigDecimal totalPaid) {
		this.totalPaid = totalPaid;
	}

	@Column(name = "transaction_ref_number")
	public String getTransactionRefNumber() {
		return this.transactionRefNumber;
	}

	public void setTransactionRefNumber(String transactionRefNumber) {
		this.transactionRefNumber = transactionRefNumber;
	}

	// bi-directional many-to-one association to TxnProduct
	@OneToMany(mappedBy = "transaction", cascade = CascadeType.ALL, orphanRemoval=true)
	public List<TxnProduct> getTxnProducts() {
		return this.txnProducts;
	}

	public void setTxnProducts(List<TxnProduct> txnProducts) {
		this.txnProducts = txnProducts;
	}

	public TxnProduct addTxnProduct(TxnProduct txnProduct) {
		getTxnProducts().add(txnProduct);
		txnProduct.setTransaction(this);

		return txnProduct;
	}

	public TxnProduct removeTxnProduct(TxnProduct txnProduct) {
		getTxnProducts().remove(txnProduct);
		txnProduct.setTransaction(null);

		return txnProduct;
	}

	// bi-directional many-to-one association to PatronInfo
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "patron_id")
	public PatronInfo getPatronInfo() {
		return this.patronInfo;
	}

	public void setPatronInfo(PatronInfo patronInfo) {
		this.patronInfo = patronInfo;
	}

	// bi-directional many-to-one association to PaymentMethod
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "payment_id")
	public PaymentMethod getPaymentMethod() {
		return this.paymentMethod;
	}

	public void setPaymentMethod(PaymentMethod paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

}